﻿using System;
using System.Collections.Generic;
using KKSG;
using UILib;
using XMainClient.UI;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient
{
	// Token: 0x02000A83 RID: 2691
	internal class XInvitationDocument : XDocComponent
	{
		// Token: 0x17002FA7 RID: 12199
		// (get) Token: 0x0600A3B1 RID: 41905 RVA: 0x001C1288 File Offset: 0x001BF488
		public override uint ID
		{
			get
			{
				return XInvitationDocument.uuID;
			}
		}

		// Token: 0x0600A3B2 RID: 41906 RVA: 0x001C129F File Offset: 0x001BF49F
		public static void Execute(OnLoadedCallback callback = null)
		{
			XInvitationDocument.AsyncLoader.AddTask("Table/Notice", XInvitationDocument.m_NoticeTable, false);
			XInvitationDocument.AsyncLoader.Execute(callback);
		}

		// Token: 0x0600A3B3 RID: 41907 RVA: 0x001C12C4 File Offset: 0x001BF4C4
		public NoticeTable.RowData GetNoticeData(NoticeType type)
		{
			return XInvitationDocument.m_NoticeTable.GetByid(this.ToID(type));
		}

		// Token: 0x0600A3B4 RID: 41908 RVA: 0x001C12E8 File Offset: 0x001BF4E8
		public NoticeTable.RowData GetNoticeData(uint id)
		{
			return XInvitationDocument.m_NoticeTable.GetByid(id);
		}

		// Token: 0x0600A3B5 RID: 41909 RVA: 0x001C1308 File Offset: 0x001BF508
		private uint ToID(NoticeType type)
		{
			return (uint)XFastEnumIntEqualityComparer<NoticeType>.ToInt(type);
		}

		// Token: 0x0600A3B6 RID: 41910 RVA: 0x001C1320 File Offset: 0x001BF520
		private bool _IsOpenSys(NoticeType type)
		{
			return NoticeType.NT_OPENSYS_BEGIN <= type && type < NoticeType.NT_OPENSYS_END;
		}

		// Token: 0x0600A3B7 RID: 41911 RVA: 0x001C1348 File Offset: 0x001BF548
		private void _SendMessage(uint channel, string content, List<ChatParam> param, bool bIsSystem = true, bool isRecruit = false, bool isDragonGuildRecruit = false)
		{
			bool flag = channel == 1U;
			if (flag)
			{
				this.m_ChatLinkData.Reset();
				this.m_ChatLinkData.channel = (ChatChannelType)channel;
				this.m_ChatLinkData.content = content;
				this.m_ChatLinkData.param = param;
				this.m_ChatLinkData.bIsSystem = bIsSystem;
				bool flag2 = DlgBase<XChatView, XChatBehaviour>.singleton.CheckWorldSendMsg(false, new ButtonClickEventHandler(this._RealSendMsg), ChatChannelType.World);
				if (flag2)
				{
					DlgBase<XChatView, XChatBehaviour>.singleton.SendChatContent(content, (ChatChannelType)channel, true, param, bIsSystem, 0UL, 0f, isRecruit, isDragonGuildRecruit);
				}
			}
			else
			{
				DlgBase<XChatView, XChatBehaviour>.singleton.SendChatContent(content, (ChatChannelType)channel, true, param, bIsSystem, 0UL, 0f, isRecruit, isDragonGuildRecruit);
			}
		}

		// Token: 0x0600A3B8 RID: 41912 RVA: 0x001C13F4 File Offset: 0x001BF5F4
		private bool _RealSendMsg(IXUIButton btn)
		{
			DlgBase<XChatView, XChatBehaviour>.singleton.SendChatContent(this.m_ChatLinkData.content, this.m_ChatLinkData.channel, true, this.m_ChatLinkData.param, this.m_ChatLinkData.bIsSystem, 0UL, 0f, false, false);
			this.m_ChatLinkData.Reset();
			return DlgBase<XChatView, XChatBehaviour>.singleton.CheckSelect(btn);
		}

		// Token: 0x0600A3B9 RID: 41913 RVA: 0x001C1460 File Offset: 0x001BF660
		public void SendGuildInvitation()
		{
			XGuildDocument specificDocument = XDocuments.GetSpecificDocument<XGuildDocument>(XGuildDocument.uuID);
			bool flag = !specificDocument.CheckInGuild();
			if (!flag)
			{
				NoticeTable.RowData noticeData = this.GetNoticeData(NoticeType.NT_INVITE_GUILD);
				bool flag2 = noticeData == null;
				if (!flag2)
				{
					List<ChatParam> list = new List<ChatParam>();
					ChatParam chatParam = new ChatParam();
					chatParam.guild = new ChatParamGuild();
					chatParam.guild.guildid = specificDocument.UID;
					chatParam.guild.guildname = specificDocument.BasicData.guildName;
					ChatParam chatParam2 = new ChatParam();
					chatParam2.link = new ChatParamLink();
					chatParam2.link.id = noticeData.linkparam;
					chatParam2.link.content = noticeData.linkcontent;
					chatParam2.guild = chatParam.guild;
					list.Add(chatParam);
					list.Add(chatParam2);
					this._SendMessage((uint)noticeData.channel, string.Format(noticeData.info, specificDocument.BasicData.guildName), list, true, true, false);
				}
			}
		}

		// Token: 0x0600A3BA RID: 41914 RVA: 0x001C156C File Offset: 0x001BF76C
		public void SendDragonGuildInvitation()
		{
			XDragonGuildDocument doc = XDragonGuildDocument.Doc;
			bool flag = !doc.IsInDragonGuild();
			if (!flag)
			{
				NoticeTable.RowData noticeData = this.GetNoticeData(NoticeType.NT_INVITE_DRAGON_GUILD);
				bool flag2 = noticeData == null;
				if (!flag2)
				{
					List<ChatParam> list = new List<ChatParam>();
					ChatParam chatParam = new ChatParam();
					chatParam.dragonguild = new ChatParamDragonGuild();
					chatParam.dragonguild.dragonguildId = doc.UID;
					chatParam.dragonguild.dragonguildname = doc.BaseData.dragonGuildName;
					ChatParam chatParam2 = new ChatParam();
					chatParam2.link = new ChatParamLink();
					chatParam2.link.id = noticeData.linkparam;
					chatParam2.link.content = noticeData.linkcontent;
					chatParam2.dragonguild = chatParam.dragonguild;
					list.Add(chatParam);
					list.Add(chatParam2);
					this._SendMessage((uint)noticeData.channel, string.Format(noticeData.info, doc.BaseData.dragonGuildName), list, true, false, true);
				}
			}
		}

		// Token: 0x0600A3BB RID: 41915 RVA: 0x001C1670 File Offset: 0x001BF870
		public void SendSpectateInvitation(uint noticeid, uint liveID, LiveType liveType, params object[] args)
		{
			NoticeTable.RowData noticeData = this.GetNoticeData(noticeid);
			bool flag = noticeData == null;
			if (!flag)
			{
				List<ChatParam> list = new List<ChatParam>();
				list.Add(new ChatParam
				{
					link = new ChatParamLink
					{
						id = noticeData.linkparam,
						content = noticeData.linkcontent
					},
// 					link = 
// 					{
// 						id = noticeData.linkparam,
// 						content = noticeData.linkcontent
// 					},
					spectate = new ChatParamSpectate()
					{
						liveid = liveID,
						livetype = (uint)liveType
					}
				});
				uint activeChannelType = (uint)DlgBase<XChatView, XChatBehaviour>.singleton.activeChannelType;
				this._SendMessage(activeChannelType, string.Format(noticeData.info, args), list, true, false, false);
			}
		}

		// Token: 0x0600A3BC RID: 41916 RVA: 0x001C1724 File Offset: 0x001BF924
		public string GetSpectateLinkString(uint noticeid, params object[] args)
		{
			NoticeTable.RowData noticeData = this.GetNoticeData(noticeid);
			bool flag = noticeData == null;
			string result;
			if (flag)
			{
				result = string.Empty;
			}
			else
			{
				string text = string.Format(noticeData.info, args);
				text = text.Replace("$L", XSingleton<XCommon>.singleton.StringCombine("[56eaef][u]", noticeData.linkcontent, "[/u][-]"));
				result = text;
			}
			return result;
		}

		// Token: 0x0600A3BD RID: 41917 RVA: 0x001C1784 File Offset: 0x001BF984
		public void SendGuildInvitationPrivate()
		{
			XGuildDocument specificDocument = XDocuments.GetSpecificDocument<XGuildDocument>(XGuildDocument.uuID);
			bool flag = !specificDocument.CheckInGuild();
			if (!flag)
			{
				NoticeTable.RowData noticeData = this.GetNoticeData(NoticeType.NT_INVITE_GUILD_PRIVATE);
				bool flag2 = noticeData == null;
				if (!flag2)
				{
					List<ChatParam> list = new List<ChatParam>();
					ChatParam chatParam = new ChatParam();
					chatParam.role = new ChatParamRole();
					chatParam.role.uniqueid = XSingleton<XAttributeMgr>.singleton.XPlayerData.RoleID;
					chatParam.role.name = XSingleton<XAttributeMgr>.singleton.XPlayerData.Name;
					chatParam.role.profession = XSingleton<XAttributeMgr>.singleton.XPlayerData.TypeID;
					ChatParam chatParam2 = new ChatParam();
					chatParam2.guild = new ChatParamGuild();
					chatParam2.guild.guildid = specificDocument.UID;
					chatParam2.guild.guildname = specificDocument.BasicData.guildName;
					ChatParam chatParam3 = new ChatParam();
					chatParam3.link = new ChatParamLink();
					chatParam3.link.id = noticeData.linkparam;
					chatParam3.link.content = noticeData.linkcontent;
					chatParam3.guild = chatParam2.guild;
					list.Add(chatParam);
					list.Add(chatParam2);
					list.Add(chatParam3);
					this._SendMessage((uint)noticeData.channel, string.Format(noticeData.info, XSingleton<XAttributeMgr>.singleton.XPlayerData.Name, specificDocument.BasicData.guildName), list, true, false, false);
				}
			}
		}

		// Token: 0x0600A3BE RID: 41918 RVA: 0x001C1910 File Offset: 0x001BFB10
		public void SendTeamInvitation(NoticeType teamType, uint teamid, uint expid, string expName)
		{
			NoticeTable.RowData noticeData = this.GetNoticeData(teamType);
			bool flag = noticeData == null;
			if (!flag)
			{
				List<ChatParam> list = new List<ChatParam>();
				list.Add(new ChatParam
				{
					team = new ChatParamTeam()
					{
						teamid = teamid,
						expeditionid = expid
					},
					link = new ChatParamLink()
					{
						id = noticeData.linkparam,
						content = noticeData.linkcontent
					}
				});
				this._SendMessage((uint)noticeData.channel, string.Format(noticeData.info, expName), list, true, false, false);
			}
		}

		// Token: 0x0600A3BF RID: 41919 RVA: 0x001C19BC File Offset: 0x001BFBBC
		public string GetOpenSysLinkString(NoticeType noticeType, params object[] args)
		{
			NoticeTable.RowData byid = XInvitationDocument.m_NoticeTable.GetByid((uint)XFastEnumIntEqualityComparer<NoticeType>.ToInt(noticeType));
			bool flag = byid == null;
			string result;
			if (flag)
			{
				result = string.Empty;
			}
			else
			{
				string text = string.Format(byid.info, args);
				text = text.Replace("$L", XSingleton<XCommon>.singleton.StringCombine("[56eaef][u]", byid.linkcontent, "[/u][-]"));
				result = text;
			}
			return result;
		}

		// Token: 0x0600A3C0 RID: 41920 RVA: 0x001C1A24 File Offset: 0x001BFC24
		public void SendOpenSysInvitation(NoticeType noticeType, params ulong[] param)
		{
			NoticeTable.RowData byid = XInvitationDocument.m_NoticeTable.GetByid((uint)XFastEnumIntEqualityComparer<NoticeType>.ToInt(noticeType));
			bool flag = byid == null;
			if (!flag)
			{
				List<ChatParam> paramList = XInvitationDocument.GetParamList(byid, param);
				int num = byid.channel;
				bool flag2 = num == -9999;
				if (flag2)
				{
					num = XFastEnumIntEqualityComparer<ChatChannelType>.ToInt(DlgBase<XChatView, XChatBehaviour>.singleton.activeChannelType);
				}
				this._SendMessage((uint)num, byid.info, paramList, true, false, false);
			}
		}

		// Token: 0x0600A3C1 RID: 41921 RVA: 0x001C1A90 File Offset: 0x001BFC90
		public void SendOpenSysInvitation(XSysDefine sys, params ulong[] param)
		{
			NoticeTable.RowData noticeData = this.GetNoticeData(sys);
			bool flag = noticeData == null;
			if (!flag)
			{
				List<ChatParam> paramList = XInvitationDocument.GetParamList(noticeData, param);
				this._SendMessage((uint)noticeData.channel, noticeData.info, paramList, true, false, false);
			}
		}

		// Token: 0x0600A3C2 RID: 41922 RVA: 0x001C1AD0 File Offset: 0x001BFCD0
		public void SendActivityInvitation(XSysDefine sys, ulong param = 0UL, bool self = true)
		{
			NoticeTable.RowData noticeData = this.GetNoticeData(sys);
			bool flag = noticeData == null;
			if (!flag)
			{
				List<ChatParam> paramList = XInvitationDocument.GetParamList(noticeData, new ulong[]
				{
					param
				});
				DlgBase<XChatView, XChatBehaviour>.singleton.SendChatContent(noticeData.info, (ChatChannelType)noticeData.channel, self, paramList, true, 0UL, 0f, false, false);
			}
		}

		// Token: 0x0600A3C3 RID: 41923 RVA: 0x001C1B24 File Offset: 0x001BFD24
		public static List<ChatParam> GetParamList(NoticeTable.RowData data, params ulong[] param)
		{
			List<ChatParam> list = new List<ChatParam>();
			ChatParam chatParam = new ChatParam();
			chatParam.link = new ChatParamLink();
			chatParam.link.id = data.linkparam;
			chatParam.link.content = data.linkcontent;
			bool flag = param != null;
			if (flag)
			{
				for (int i = 0; i < param.Length; i++)
				{
					chatParam.link.param.Add(param[i]);
				}
			}
			list.Add(chatParam);
			return list;
		}

		// Token: 0x0600A3C4 RID: 41924 RVA: 0x001C1BB4 File Offset: 0x001BFDB4
		public NoticeTable.RowData GetNoticeData(XSysDefine sys)
		{
			NoticeTable.RowData rowData = null;
			uint num = 0U;
			while ((ulong)num < (ulong)((long)XInvitationDocument.m_NoticeTable.Table.Length))
			{
				rowData = XInvitationDocument.m_NoticeTable.Table[(int)num];
				bool flag = rowData.linkparam == (uint)sys && this._IsOpenSys((NoticeType)rowData.id);
				if (flag)
				{
					break;
				}
				num += 1U;
				rowData = null;
			}
			return rowData;
		}

		// Token: 0x0600A3C5 RID: 41925 RVA: 0x001C1C18 File Offset: 0x001BFE18
		public string ParseLink(ChatParam param)
		{
			bool flag = param.link == null;
			string result;
			if (flag)
			{
				result = "";
			}
			else
			{
				string content = param.link.content;
				bool flag2 = param.team != null;
				if (flag2)
				{
					result = XLabelSymbolHelper.FormatTeam(content, (int)param.team.teamid, param.team.expeditionid);
				}
				else
				{
					bool flag3 = param.guild != null;
					if (flag3)
					{
						result = XLabelSymbolHelper.FormatGuild(content, param.guild.guildid);
					}
					else
					{
						bool flag4 = param.dragonguild != null;
						if (flag4)
						{
							result = XLabelSymbolHelper.FormatDragonGuild(content, param.dragonguild.dragonguildname);
						}
						else
						{
							bool flag5 = param.spectate != null;
							if (flag5)
							{
								result = XLabelSymbolHelper.FormatSpectate(content, (int)param.spectate.liveid, (int)param.spectate.livetype);
							}
							else
							{
								result = XLabelSymbolHelper.FormatUI(content, (ulong)param.link.id, param.link.param);
							}
						}
					}
				}
			}
			return result;
		}

		// Token: 0x0600A3C6 RID: 41926 RVA: 0x001C1D14 File Offset: 0x001BFF14
		public static void OnUIHyperLinkClick(string param)
		{
			bool flag = DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.IsLoaded();
			if (flag)
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("NOT_IN_HALL_SPECTATE"), "fece00");
			}
			else
			{
				bool flag2 = XSingleton<XGame>.singleton.CurrentStage.Stage != EXStage.Hall;
				if (flag2)
				{
					XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("NOT_IN_HALL_STAGE"), "fece00");
				}
				else
				{
					SceneType sceneType = XSingleton<XScene>.singleton.SceneType;
					bool flag3 = sceneType == SceneType.SCENE_FAMILYGARDEN && XHomeCookAndPartyDocument.Doc.CurBanquetID > 0U;
					if (flag3)
					{
						XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("HomeFeasting"), "fece00");
					}
					else
					{
						ulong num = 0UL;
						List<ulong> list = new List<ulong>();
						bool flag4 = XLabelSymbolHelper.ParseUIParam(param, ref num, ref list);
						if (flag4)
						{
							XSingleton<XDebug>.singleton.AddLog("UI link clicked: ", param, null, null, null, null, XDebugColor.XDebug_None);
							bool flag5 = !XSingleton<XGameSysMgr>.singleton.IsSystemOpened((XSysDefine)num);
							if (flag5)
							{
								XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("SYSTEM_NOT_OPEN"), "fece00");
							}
							else
							{
								XSysDefine xsysDefine = (XSysDefine)num;
								if (xsysDefine <= XSysDefine.XSys_Home_Feast)
								{
									if (xsysDefine == XSysDefine.XSys_Personal_Career)
									{
										DlgBase<PersonalCareerView, PersonalCareerBehaviour>.singleton.OpenOtherPush(list);
										goto IL_29A;
									}
									if (xsysDefine == XSysDefine.XSys_Home_Feast)
									{
										bool flag6 = list.Count == 1;
										if (flag6)
										{
											string name = "";
											bool flag7 = list[0] == XSingleton<XAttributeMgr>.singleton.XPlayerData.EntityID;
											if (flag7)
											{
												name = XSingleton<XAttributeMgr>.singleton.XPlayerData.Name;
											}
											else
											{
												XFriendData friendDataById = DlgBase<XFriendsView, XFriendsBehaviour>.singleton.GetFriendDataById(list[0]);
												bool flag8 = friendDataById != null;
												if (flag8)
												{
													name = friendDataById.name;
												}
											}
											HomeMainDocument.Doc.ReqEnterHomeScene(list[0], name);
										}
										goto IL_29A;
									}
								}
								else
								{
									if (xsysDefine == XSysDefine.XSys_Wedding)
									{
										bool flag9 = list.Count == 1;
										if (flag9)
										{
											XWeddingDocument.Doc.WeddingInviteOperate(WeddingInviteOperType.Wedding_Apply, XSingleton<XAttributeMgr>.singleton.XPlayerData.RoleID, list[0]);
										}
										goto IL_29A;
									}
									if (xsysDefine == XSysDefine.XSys_GuildDialyDonate)
									{
										bool flag10 = list.Count == 1;
										if (flag10)
										{
											XGuildDonateDocument.Doc.ShowViewWithID((uint)list[0], GuildDonateType.DailyDonate);
										}
										goto IL_29A;
									}
									if (xsysDefine == XSysDefine.XSys_GuildWeeklyDonate)
									{
										bool flag11 = list.Count == 1;
										if (flag11)
										{
											XGuildDonateDocument.Doc.ShowViewWithID((uint)list[0], GuildDonateType.WeeklyDonate);
										}
										goto IL_29A;
									}
								}
								XSingleton<XGameSysMgr>.singleton.OpenSystem((XSysDefine)num, 0UL);
								IL_29A:;
							}
						}
					}
				}
			}
		}

		// Token: 0x0600A3C7 RID: 41927 RVA: 0x001C1FBC File Offset: 0x001C01BC
		public static void OnSpectateClick(string param)
		{
			bool flag = DlgBase<SpectateSceneView, SpectateSceneBehaviour>.singleton.IsLoaded();
			if (flag)
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("NOT_IN_HALL_SPECTATE"), "fece00");
			}
			else
			{
				bool flag2 = XSingleton<XGame>.singleton.CurrentStage.Stage != EXStage.Hall;
				if (flag2)
				{
					XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("NOT_IN_HALL_STAGE"), "fece00");
				}
				else
				{
					bool flag3 = XLabelSymbolHelper.ParseSpectateParam(param, ref XInvitationDocument.mLiveID, ref XInvitationDocument.mType);
					if (flag3)
					{
						XSingleton<XDebug>.singleton.AddLog(string.Concat(new object[]
						{
							"xxxxxxxxxxx=> liveid: ",
							XInvitationDocument.mLiveID,
							" type: ",
							XInvitationDocument.mType
						}), null, null, null, null, null, XDebugColor.XDebug_None);
						DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.SetVisible(true, true);
						DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.SetSingleButtonMode(false);
						string @string = XStringDefineProxy.GetString("Spectate_Sure");
						string string2 = XStringDefineProxy.GetString(XStringDefine.COMMON_OK);
						string string3 = XStringDefineProxy.GetString(XStringDefine.COMMON_CANCEL);
						DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.SetLabelsWithSymbols(@string, string2, string3);
						DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.SetModalCallback(new ButtonClickEventHandler(XInvitationDocument.OnGoSpectate), null);
					}
				}
			}
		}

		// Token: 0x0600A3C8 RID: 41928 RVA: 0x001C20EC File Offset: 0x001C02EC
		private static bool OnGoSpectate(IXUIButton btn)
		{
			DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.SetVisible(false, true);
			XSpectateDocument specificDocument = XDocuments.GetSpecificDocument<XSpectateDocument>(XSpectateDocument.uuID);
			specificDocument.EnterSpectateBattle((uint)XInvitationDocument.mLiveID, (LiveType)XInvitationDocument.mType);
			return true;
		}

		// Token: 0x0600A3C9 RID: 41929 RVA: 0x000FEEFC File Offset: 0x000FD0FC
		protected override void OnReconnected(XReconnectedEventArgs arg)
		{
		}

		// Token: 0x04003B58 RID: 15192
		public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("InvitationDocument");

		// Token: 0x04003B59 RID: 15193
		public static XTableAsyncLoader AsyncLoader = new XTableAsyncLoader();

		// Token: 0x04003B5A RID: 15194
		private static NoticeTable m_NoticeTable = new NoticeTable();

		// Token: 0x04003B5B RID: 15195
		private XInvitationDocument.InvitationChatLinkData m_ChatLinkData = new XInvitationDocument.InvitationChatLinkData();

		// Token: 0x04003B5C RID: 15196
		private static int mLiveID = 0;

		// Token: 0x04003B5D RID: 15197
		private static int mType = 1;

		// Token: 0x0200198D RID: 6541
		private class InvitationChatLinkData
		{
			// Token: 0x0601101E RID: 69662 RVA: 0x00453658 File Offset: 0x00451858
			public void Reset()
			{
				bool flag = this.param != null;
				if (flag)
				{
					this.param.Clear();
				}
				this.param = null;
			}

			// Token: 0x04007EEA RID: 32490
			public ChatChannelType channel;

			// Token: 0x04007EEB RID: 32491
			public string content;

			// Token: 0x04007EEC RID: 32492
			public List<ChatParam> param;

			// Token: 0x04007EED RID: 32493
			public bool bIsSystem;
		}
	}
}
